package HashPackage2;

import java.util.HashMap;

/**
 * @author Lzm
 * @version 1.0
 */
public class fourSumCount_ {

  public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
    // 剪枝
    int count = 0;
    if (nums1.length == 0 || nums2.length == 0 || nums3.length == 0 || nums4.length == 0 ){
      return count;
    }
    HashMap<Integer,Integer> hashMap = new HashMap<>();
    for (int i = 0; i < nums1.length; i++) {
      for (int j = 0; j < nums2.length; j++) {
        Integer value = hashMap.get(nums1[i] + nums2[j]);
        if (value != null){
          hashMap.put(nums1[i] + nums2[j] , value + 1);
        }
        else{
          hashMap.put(nums1[i] + nums2[j] ,1);
        }
      }
    }
    for (int i = 0; i < nums3.length; i++) {
      for (int j = 0; j < nums4.length; j++) {
        if (hashMap.containsKey(0 - nums3[i] - nums4[j])){
          count+= hashMap.get(0 - nums3[i] - nums4[j]);
        }
      }
    }
    return count;
  }
}
